<template>
  <div class="goodslist">
    <div class="goodsitem" v-for="(item,index) in arr" :key="index">
      <router-link :src="item.img_url" :to="'/home/Imgdetails/'+item.id" tag="img"></router-link>
      <h1 class="title">{{item.title}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">{{item.market_price}}元</span>
          <span class="old">{{item.sell_price}}元</span>
        </p>
        <p class="sell">
          <span class>热卖中</span>
          <span class>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
<button class="btn" @click="getbtn">加载更多</button> 
  </div>
</template>

<script>
export default {
  data() {
    return {
        pageindex:1,
        arr:[]
    };
  },
  methods: {
     goodlist(){
          this.$axios.get('/api/getgoods?pageindex'+this.pageindex).then(res=>{
              
              this.arr=this.arr.concat(res.data.message)
              console.log(this.arr)
          })
     },
     getbtn(){
         this.pageindex++;
         this.goodlist()
         
     }
  },
  created () {
      this.goodlist()
  }
};
</script>

<style scoped lang="scss">
.goodslist {
    min-height: 303px;
  display: flex;
  flex-wrap: wrap;
  .goodsitem {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 2px;
      border: 1px solid pink;
    width: 50%;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
      text-align: center;
    }
    .info {
      background-color: #ccc;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          font-weight: 800;
          color: red;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
  .btn{
      width: 100%;
      text-align: center;
      color: red;
      background-color: pink;
  }
}
</style>
